from django.db import models
from apps.common.base.models import BaseModel
from apps.account.models import Account

class Conversation(BaseModel):

    '''会话模型'''
    conversationType = (
        ("system", "系统消息"),
        ("jytz", "交易通知"),
        ("custom", "用户消息")
    )
    conversationType = models.CharField("消息类型", max_length=100, choices=conversationType, default="custom")
    showName=models.CharField("会话名称", max_length=200, blank=True, null=True)
    faceUrl=models.CharField("会话头像", max_length=1000, blank=True, null=True)

    userA = models.ForeignKey(Account, related_name='userA_conversation', verbose_name='userA', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    userB = models.ForeignKey(Account, related_name='userB_conversation', verbose_name='userB', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    lastMessage = models.ForeignKey('Message', related_name='lastMessage_conversation', verbose_name='最后一条消息', on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)

    class Meta:
        verbose_name = '会话模型'
        verbose_name_plural = verbose_name